<template>
	<view
		class="container"
		:style="{
			background: `linear-gradient(to bottom, ${templateConfig.page.themeColor} 300rpx, #F6D5C3 500rpx, #f8f8f8 700rpx) `
		}"
	>
		<view class="title1">
			<view class="left">
				<text class="text2">{{ userInfo.integral }}</text>
				<text class="text3">积分</text>
			</view>
			<view class="right" @click="gotoRecord">
				<text>积分明细</text>
				<u-icon name="arrow-right" color="#fff" size="14"></u-icon>
			</view>
		</view>

		<scroll-view
			scroll-y="true"
			class="main_scroll"
			:refresher-triggered="refresher_show"
			@refresherrefresh="refresherrefresh"
			@scrolltolower="scrolltolower"
			:scroll-with-animation="true"
			:refresher-enabled="true"
			:scroll-top="scrollTop"
		>
			<view class="main_content">
				<view class="goodsList_box">
					<view
						class="goods_item"
						@click="gotoDetail(item.id)"
						v-for="(item, index) in pointGoodsList"
						:key="index"
					>
						<view class="goodsTitle_box">
							<view class="image">
								<image :src="item.previewUrl" lazy-load mode="aspectFill"></image>
							</view>
							<view class="title">
								<text class="title_text">{{ item.goodsName }}</text>
								<text class="desc_text">{{ item.goodsRemarks }}</text>
								<view class="hotSale">
									<text :style="{color:templateConfig.page.themeColor}">热销</text>
								</view>

								<view class="price">
									<view class="">
										<text :style="{color:templateConfig.page.themeColor}">{{ item.goodsPrice }}积分</text>
									</view>
									<view class="exchangeImme" :style="{background:templateConfig.page.themeColor}">立即兑换</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import { getIntegralGoodsList, searchUserInfoById } from '../../static/utils/api.js';
import { getRgb } from '../../static/utils/utils.js';
export default {
	data() {
		return {
			userInfo: uni.getStorageSync('userInfo'),
			templateConfig: uni.getStorageSync('templateConfig'),
			couponList: [],
			nowBusinessInfo: {},
			couponIndex: -1,
			orderPage: {
				page: 1,
				sizes: 10,
				total: 0,
				hasNextPage: false
			},
			pointGoodsList: [],
			refresher_show: false
		};
	},
	onLoad() {},
	onShow() {
		this.nowBusinessInfo = uni.getStorageSync('nowBusinessInfo');
		this.getgoodsList(true);
		this.getuserInfo();
	},
	methods: {
		getRgb,
		// 获取个人信息
		getuserInfo() {
			let data = {
				userId: uni.getStorageSync('userInfo').id
			};
			searchUserInfoById(data).then((res) => {
				if (res.code == 200) {
					this.userInfo = res.body;
				}
			});
		},
		gotoDetail(id) {
			uni.navigateTo({
				url: `/pages/index/detail?id=${id}`
			});
		},
		gotoRecord() {
			uni.navigateTo({
				url: `/packageA/integral/integralRecord`
			});
		},
		// 获取积分兑换商品的商品列表
		getgoodsList(clear) {
			let postdata = {
				businessId: this.nowBusinessInfo.businessId.toString(),
				page: this.orderPage.page
			};
			getIntegralGoodsList(postdata).then((res) => {
				if (res.code == 200) {
					this.orderPage.total = res.body.pages;
					this.orderPage.hasNextPage = res.body.hasNextPage;
					let list = res.body.list;
					if (clear) {
						this.pointGoodsList = list;
					} else {
						this.pointGoodsList = this.pointGoodsList.concat(list);
					}

					if (this.refresher_show) {
						this.refresher_show = false;
					}
				}
			});
		},
		// 下拉刷新
		refresherrefresh() {
			this.refresher_show = true;
			this.orderPage.page = 1;
			this.getgoodsList(true);
		},
		// 滚动到底部加载更多
		scrolltolower() {
			if (!this.orderPage.hasNextPage) return;
			this.orderPage.page++;
			this.getgoodsList();
		}
	}
};
</script>

<style lang="scss">
// page{
// 	width: 100vw;
// 	height: 100vh;
// 	background: linear-gradient(to bottom, #FF0006 300rpx, #F6D5C3 500rpx, #f8f8f8 700rpx);
// }
</style>

<style lang="scss" scoped>
.container {
	width: 100vw;
	.title1 {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		height: 15vh;
		position: relative;
		.left {
			margin-top: 50rpx;
			display: flex;
			align-items: flex-end;
			// justify-content:center ;

			.text2 {
				font-size: 60rpx;
				font-weight: bold;

				color: #fff;
			}
			.text3 {
				margin-bottom: 10rpx;
				color: #fff;
			}
		}
		.right {
			position: absolute;
			top: 40rpx;
			right: 40rpx;
			height: 70rpx;
			padding: 0 16rpx;
			border-radius: 35rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			background-color: rgba(255, 255, 255, 0.4);
			color: #fff;
		}
	}

	.main_scroll {
		height: 85vh;
		width: 100%;
		box-sizing: border-box;
		.main_content {
			width: 100%;
			.goodsList_box {
				box-sizing: border-box;
				margin-bottom: 30rpx;
				padding: 0 20rpx;
				padding-bottom: 40rpx;
				.goods_item {
					padding: 20rpx 20rpx;
					box-sizing: border-box;
					margin-top: 20rpx;
					margin-bottom: 20rpx;
					background-color: #fff;
					border-radius: 20rpx;

					.goodsTitle_box {
						display: flex;
						align-items: center;

						.title {
							display: flex;
							justify-content: space-between;
							padding: 0 30rpx;
							box-sizing: border-box;
							margin-top: 20rpx;

							.left {
								display: flex;
								align-items: center;

								.text1 {
									color: #fff;
								}
								.text2 {
									font-size: 60rpx;
									font-weight: bold;
									color: #fff;
								}
							}
							.right {
								height: 70rpx;
								padding: 0 16rpx;
								border-radius: 35rpx;
								display: flex;
								justify-content: center;
								align-items: center;
								background-color: rgba(255, 255, 255, 0.4);
								color: #fff;
							}
						}

						.image {
							width: 220rpx;
							height: 220rpx;
							border-radius: 20rpx;

							image {
								width: 100%;
								height: 100%;
								border-radius: 20rpx;
							}
						}

						.title {
							flex: 1;
							display: flex;
							flex-direction: column;
							margin-left: 20rpx;
							box-sizing: border-box;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;

							.title_text {
								font-size: 30rpx;
								padding-bottom: 14rpx;
								overflow: hidden;
								white-space: normal;
								text-overflow: ellipsis;
								-webkit-line-clamp: 2;
								-webkit-box-orient: vertical;
							}
							.desc_text {
								color: #7a7a7a;
								font-size: 24rpx;
								overflow: hidden;
								text-overflow: ellipsis;
							}
							.couponAfter {
								text {
									padding: 4rpx 16rpx;
									background-color: #ff0000;
									color: #fff;
									font-size: 26rpx;
									border-radius: 10rpx;
								}
							}
							.hotSale {
								padding: 4rpx 0;

								text {
									padding: 4rpx 4rpx;
									background-color: #ffdee2;
									color: #ff0000;
									font-size: 22rpx;
									border-radius: 10rpx;
								}
							}
							.coupondesc {
								display: flex;
								align-items: center;
								margin-top: 6rpx;

								.coupon {
									border: 1rpx solid #ff0000;
									display: flex;
									align-items: center;
									border-radius: 6rpx;

									.text1 {
										width: 26rpx;
										padding: 4rpx 4rpx;
										background-color: #ff0000;
										color: #fff;
										font-size: 22rpx;
										border-radius: 6rpx;
									}
									.text2 {
										padding: 0 4rpx;
										font-size: 22rpx;
										color: #ff0000;
									}
								}
							}
							.price {
								margin-top: 20rpx;
								font-size: 34rpx;
								color: #ff0000;
								font-weight: bold;
								display: flex;
								justify-content: space-between;
								align-items: center;

								span {
									font-size: 30rpx;
								}
								.image {
									width: 50rpx;
									height: 50rpx;
								}
								.exchangeImme {
									background-color: #df282f;
									color: #fff;
									font-size: 26rpx;
									border-radius: 40rpx;
									padding: 8rpx 30rpx;
								}
							}
						}
					}
				}
				.goods_item:last-child {
					border: none;
				}
			}
		}
	}
}
</style>
